import Vue from 'vue'
import Levels from './rule-level'
import Types from './rule-type'
import Utils from './_utils'
import _ from 'lodash'

const rule = 'min'

/*
* config {
*   min: undefined // Function/ComparableObject
* }
* */

export default {
  priority: Levels.MEDIUM_LEVEL + 1, // validate input chars first
  validate: function (value, config, model, formModel, filed, fieldScope) {
    let errorParams = {}
    return {
      valid: Utils.validateWrapper(config.min, null, value, config, model, formModel, (params, value, model, formModel) => {
        Vue.set(errorParams, 'min', params)
        return _.isNil(value) || value === '' || value > params || value === params
      }),
      errorTemplate: undefined,
      errorParams
    }
  },
  rule: rule,
  type: Types.ATTRIBUTE
}
